import { apiShopMange } from 'js/api'
import { storage } from 'js/util'

export default {
  state: {
    shopTypeList: (storage.get('shopTypeList') || [])
  },
  getters: {
    shopTypeList: state => state.shopTypeList
  },
  actions: {
    /**
     * 获取店铺类型
     */
    fetchShopType({ state }) {
      if (storage.get('shopTypeList')) return
      apiShopMange.apiShopType().then(data => {
        const list = data.data || {}
        if (list && list.length == 0) return
        state.shopTypeList = list.map(type => {
          return {
            value: type.id,
            label: type.dictName
          }
        })
        storage.set('shopTypeList', state.shopTypeList)
      })
    }
  }
}